package com.atguigu.spzx.common.exception;

import com.atguigu.spzx.model.vo.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Result commonExceptionHandler(Exception e){
        log.info("被Exception通用异常通知捕获");
        log.error(e.getMessage());
        e.printStackTrace();
        return Result.fail(e.getMessage());
    }

    @ExceptionHandler(NullPointerException.class)
    public Result nullPointerExceptionHandler(NullPointerException e){
        log.info("被NullPointerException通用异常通知捕获");
        log.error(e.getMessage());
        return Result.fail();
    }

    @ExceptionHandler(GuiguException.class)
    public Result guiguException(GuiguException e){
        log.info("被guiguException通用异常通知捕获");
        log.error(e.getMessage());
        e.printStackTrace();
        return Result.fail(e.getMessage());
    }
}
